package cn.caskm.souvenirshopsystem.controller.admin;

import cn.caskm.souvenirshopsystem.domain.Result;
import cn.caskm.souvenirshopsystem.domain.dto.PageDTO;
import cn.caskm.souvenirshopsystem.domain.po.SeckillGoods;
import cn.caskm.souvenirshopsystem.domain.query.SeckillGoodsQuery;
import cn.caskm.souvenirshopsystem.domain.vo.SeckillGoodsVO;
import cn.caskm.souvenirshopsystem.service.SeckillGoodsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/seckill")
@RequiredArgsConstructor
public class AdminSeckillController {

    private final SeckillGoodsService seckillGoodsService;

    @GetMapping("/page")
    public Result<PageDTO<SeckillGoodsVO>> page(SeckillGoodsQuery query) {
        return seckillGoodsService.page(query);
    }

    @GetMapping("/detail/{seckillId}")
    public Result<SeckillGoodsVO> getSeckillGoodsDetail(@PathVariable("seckillId") Integer seckillId) {
        return seckillGoodsService.getSeckillGoodsDetail(seckillId);
    }

    @PostMapping("/create")
    public Result<Void> createSeckillGoods(@RequestBody SeckillGoods seckillGoods) {
        return seckillGoodsService.createSeckillGoods(seckillGoods);
    }

    @PutMapping("/update")
    public Result<Void> updateSeckillGoods(@RequestBody SeckillGoods seckillGoods) {
        return seckillGoodsService.updateSeckillGoods(seckillGoods);
    }

    @DeleteMapping("/{seckillId}")
    public Result<Void> deleteSeckillGoods(@PathVariable("seckillId") Integer seckillId) {
        return seckillGoodsService.deleteSeckillGoods(seckillId);
    }

    @PutMapping("/updateStatus/{seckillId}")
    public Result<Void> updateSeckillStatus(@PathVariable("seckillId") Integer seckillId,
                                          @RequestParam("status") String status) {
        return seckillGoodsService.updateSeckillStatus(seckillId, status);
    }

}
